export default class ExelceEvent {
    constructor(_designerRef, _context) {
        this.designerRef = _designerRef;
        this.context = _context;

    }

    selectionEvent(rowIndex, colIndex, row2Index, col2Index) {
        let cellDef = this.context.getCell(rowIndex, colIndex);
        if (!cellDef) {
            return;
        }
        this.designerRef.excel.type = cellDef.value.type;
        this.designerRef.excel.coordinate = (cellDef.x + "," + cellDef.y);
        this.designerRef.excel.excelValue = cellDef.value.exps;
        this.designerRef.excel.width = cellDef.value.width;
        this.designerRef.excel.height = cellDef.value.height;
        this.designerRef.excel.x = cellDef.x;
        this.designerRef.excel.y = cellDef.y;
    }

    rowResizeEvent(currentRow, newSize) {
        let hot = this.context.hot;
        let rowHeights = hot.getSettings().rowHeights;
        let newRowHeights = [].concat(rowHeights);
        newRowHeights.splice(currentRow, 1, newSize);
        hot.updateSettings({
            rowHeights: newRowHeights,
            manualRowResize: newRowHeights
        });
        if (currentRow == this.designerRef.excel.y) {
            this.designerRef.excel.height = newSize;
        }
        this.context.refreshCellHeight(currentRow,newSize);
    }

    columnResizeEvent(currentColumn, newSize) {
        let hot = this.context.hot;
        let colWidths = hot.getSettings().colWidths;
        let newColWidths = [].concat(colWidths);
        newColWidths.splice(currentColumn, 1, newSize);
        hot.updateSettings({
            colWidths: newColWidths,
            manualColumnResize: newColWidths
        });
        if (currentColumn == this.designerRef.excel.x) {
            this.designerRef.excel.width = newSize;
        }
        this.context.refreshCellWidth(currentColumn,newSize);

    }

}
